<!--{template /module/admin/view/head}-->
<div id="left_layout">
	<div id="main_content" class="container-fluid">
		<!--{template /module/admin/view/head_nav}-->
		<div class="row-fluid">
			<div class="well widget">
				<div class="widget-header">
					<h3 class="title">{lang user.group.view.header}</h3>
				</div>
				<div class="widget-content">
					<div class="action-wrapper">
						<div class="pull-left">
							<a href="javascript:void(null);" id="btn_submit" class="btn btn-small btn-primary" {$dispatches[operations][edit]}>{lang admin.operation.submit}</a>
							<a href="javascript:void(null);" id="btn_delete_list" class="btn btn-small" {$dispatches[operations][delete]}>{lang admin.operation.delete}</a>
							
							<span class="muted">
								{lang user.group.view.tips}
							</span>
						</div>
					</div>
					
					<hr/>
					<form id="frm_grid" name="frmGrid" action="{$ADMIN_SCRIPT}/user/group" method="post">
					<table class="table table-hover">
						<thead>
							<tr>
								<th width="20"><input type="checkbox" class="fancy" name="cbxAll"/></th>
								<th width="80">{lang user.group.view.th.stars}</th>
					            <th width="80">{lang user.group.view.th.scorelow}</th>
					            <th width="80">{lang user.group.view.th.scoreheight}</th>
					            <th width="100">{lang user.group.view.th.identity}</th>
					            <th width="100">{lang user.group.view.th.percent}</th>
					            <!--{if $setting['Application'] == 'b2c'}-->
					            <th width="60">{lang user.group.view.th.deliverfree}</th>
					            <!--{/if}-->
					            <th>{lang user.group.view.th.cname}</th>
							</tr>
						</thead>
						<tbody id="tbl_body">
							<!--{loop $groups $_loop $group}-->
							<tr class="item-row">
								<td>
				                	<input type="checkbox" class="fancy" identity="{$group[IDENTITY]}" name="cbxItem[]"  cname="{$group[CNAME]}" value="{$group[GROUPID]}" />
				                </td>
				                <td>
					                <input type="text"  class="input-mini"  name="stars[{$group[GROUPID]}]" value="{$group[STARS]}" />
					            </td>
					            <td>
					            	<input type="text"  class="input-mini"  name="scorelow[{$group[GROUPID]}]" value="{$group[SCORELOW]}" />
					            </td>
					            <td>
					            	<input type="text"  class="input-mini"  name="scorehigh[{$group[GROUPID]}]" value="{$group[SCOREHIGH]}" />
					            </td>
					            <td>
					                <input type="text"  class="input-small"  name="identity[{$group[GROUPID]}]" value="{$group[IDENTITY]}" />
					            </td>
					            <td>
					                <input type="text"  class="input-mini"  name="percent[{$group[GROUPID]}]" value="{$group[PERCENT]}" />%
					            </td>
					            <!--{if $setting['Application'] == 'b2c'}-->
					            <td>
					            	<input type="checkbox" class="fancy" name="deliverfree[{$group[GROUPID]}]" value="1" {if $group[DELIVERFREE]}checked="checked"{/if}/>
					            </td>
					            <!--{/if}-->
					            <td>
					            	<input type="text" 	class="input input-small" name="cname[{$group[GROUPID]}]" value="{$group[CNAME]}"/>
					            </td>
							</tr>
							<!--{/loop}-->
							<!--{if count($groups) == 0}-->
						        <tr>
						            <td colspan="7">
						                * {lang admin.operation.empty}
						            </td>
						        </tr>
						    <!--{/if}-->
						    <tr>
					        	<td>{lang user.group.view.view.add}</td>
					             <td>
					                <input type="text"  class="input-mini" name="newstars[]" value="" />
					            </td>
					            <td>
					            	<input type="text"  class="input-mini" name="newscorelow[]" value="" />
					            </td>
					            <td>
					            	<input type="text"  class="input-mini" name="newscorehigh[]" value="" />
					            </td>
					            <td>
					            	<input type="text"  class="input-small" name="newidentity[]" value="" />
					            </td>
					            <td>
					            	<input type="text"  class="input-mini" name="newpercent[]" value="" />%
					            </td>
					            <!--{if $setting['Application'] == 'b2c'}-->
					            <td>
					            	<input type="checkbox" class="fancy" name="newdeliverfree[]" value="1"/>
					            </td>
					            <!--{/if}-->
					            <td>
					            	<input type="text" 	class="input input-small" name="newcname[]" value=""/>
					            </td>
					        </tr>
						</tbody>
					</table>
					</form>
					
					<div class="action-wrapper">
						<div class="pull-left">
							<a href="javascript:void(null);" id="btn_add" class="btn btn-small" {$dispatches[operations][add]} >{lang user.group.view.operation.add}</a>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>

<script>
$(function(){
	$('.fancy').uniform();
	
	$('#btn_submit').click(function(){
		$('#frm_grid').submit();
	});
	
	$('#btn_delete_list').click(function(){
		if($("#frm_grid input[name='cbxItem[]']:checked").length > 0){
			var tempHTML = '<p>';
			$("#frm_grid input[name='cbxItem[]']:checked").each(function(){
				tempHTML += $(this).attr('cname') + '； ';
			});
			
			tempHTML += '</p>';
			
			$.dialog({submit:'{lang admin.operation.delete}', message:'<p>{lang user.group.view.operation.delete.message}</p>' + tempHTML, callback:function(){
				$('#modal_dialog .btn-primary').click(function(){
					$('#frm_grid').attr('action', '{$ADMIN_SCRIPT}/user/group&do=delete_list');
					$('#frm_grid').submit();
				});
			}});
		}else $.dialog({message:'{lang user.group.view.operation.empty}'});
	});
	 
	$("#frm_grid input[name='cbxAll']").click(function(){
		if(this.checked){
			$('#frm_grid .item-row').addClass('warning');
			$("#frm_grid input[name='cbxItem[]']").attr('checked', true).parent().addClass('checked');
		}else{
			$('#frm_grid .item-row').removeClass('warning');
			$("#frm_grid input[name='cbxItem[]']").attr('checked', false).parent().removeAttr('class');
		}
	});
	
	$("#frm_grid input[name='cbxItem[]']").click(function(){
		if(this.checked) $(this).parent().parent().parent().parent().addClass('warning');
		else $(this).parent().parent().parent().parent().removeClass('warning');
	});
	
	$('#btn_add').click(function(){
    	var tbody = $('#tbl_body').get(0);
    	var tempInsertRow = tbody.rows[tbody.rows.length - 1];
    	var tempNewRow = tempInsertRow.cloneNode(true);
    	tempNewRow.style.display = '';
    	
    	var inputs = tempNewRow.getElementsByTagName('input');
    	for(var i = 0; i < inputs.length; i++){
    		if(inputs[i].name.indexOf('newcname') != -1 
    			|| inputs[i].name.indexOf('newstars') != -1 
    			|| inputs[i].name.indexOf('newscorelow') != -1 
    			|| inputs[i].name.indexOf('newscorehigh') != -1 
    			|| inputs[i].name.indexOf('newidentity') != -1 
    			|| inputs[i].name.indexOf('newpercent') != -1) inputs[i].value = '';
    	}
    	
    	tbody.insertBefore(tempNewRow, tbody.rows[tbody.rows.length - 1]);
    });
});
</script>
<!--{template /module/admin/view/foot}-->